from typing import Optional

from pydantic import BaseModel, Field
from sqlalchemy import Column, String, BigInteger, Text
from toollib.utils.now2timestamp_ import now2timestamp

from app.datatype import DeclBase, filter_fields
from app.initializer import g


class Session(DeclBase):
    __tablename__ = "session"

    #自增主键
    id = Column(BigInteger, primary_key=True, autoincrement=True, comment="主键")
    session_name = Column(Text, nullable=False, comment="名称")
    user_id = Column(String(20), nullable=False, comment="用户ID")
    created_at = Column(BigInteger, default=now2timestamp, comment="创建时间")
    updated_at = Column(BigInteger, default=now2timestamp, onupdate=now2timestamp, comment="更新时间")
    #删除状态
    is_deleted = Column(BigInteger, default=0, comment="删除状态，0未删除，1已删除")
    #是否置顶
    is_top = Column(BigInteger, default=0, comment="是否置顶，0否，1是")






class SessionCreateMdl(BaseModel):
    session_name: str = Field(..., title="会话名称", description="会话名称")
    user_id: Optional[str]  = Field(default=None, title="用户ID", description="用户ID")

class SessionUpdateMdl(BaseModel):
    id: int = Field(..., title="会话ID", description="会话ID")
    session_name: str = Field(..., title="会话名称", description="会话名称")
    is_top: int = Field(0, title="是否置顶", description="是否置顶，0否，1是")
    @classmethod
    def response_fields(cls):
        return filter_fields(
            cls,
            exclude=[]
        )

class SessionDeleteMdl(BaseModel):
    id: int = Field(..., title="会话ID", description="会话ID")

    @classmethod
    def response_fields(cls):
        return filter_fields(
            cls,
            exclude=[]
        )

class SessionListMdl(BaseModel):
    # #
    id: int = Field(default = 1, title="会话id", description="会话id")
    session_name: str = Field(default = 1, title="会话name", description="会话name")
    user_id: str = Field(default = 1, title="用户id", description="用户id")
    created_at: int = Field(default = 1, title="创建时间", description="创建时间")
    updated_at: int = Field(default = 1, title="修改时间", description="修改时间")
    is_top: int = Field(default = 0, title="是否置顶", description="是否置顶，0否，1是")

    @classmethod
    def response_fields(cls):
        return filter_fields(
            cls,
            exclude=[]
        )